﻿using System;

using Fuse8.DomainFramework.Common.Locator;
using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.BusinessService;

namespace Fuse8.DomainFramework.Configuration.Fluent
{
    /// <summary>
    /// 
    /// </summary>
    public class TestEntity : Int32EntityObject
    { }

    /// <summary>
    /// 
    /// </summary>
    public class TestEntityBusinessServiceService : BaseBusinessService<TestEntity, int>
    { }
    
    /// <summary>
    /// 
    /// </summary>
    public class TestMate
    {
        /// <summary>
        /// 
        /// </summary>
        public void Configuration()
        {
            FrameworkConfigurationBuilder.Configure()
                .UseDependencyContainer()
                    .SetLocatorProvider(
                        () =>
                        {
                            return new RegistryServiceLocator();
                        })
                .BusinessServicesConfiguration()
                    .RegisterBusinessService(new TestEntityBusinessServiceService())
                    .DataAccessConfiguration().SetDefaultUnitOfWorkFactory(For<IFrameworkDataRepositoryType>.Use.InMemory())
                .Build();
        }
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class FrameworkConfigurationBuilder : 
        IFrameworkConfigurationBuilder,
        IFrameworkConfigurationServicesBuilder,
        IFrameworkConfigurationDependencyContainerBuilder,
        IFrameworkConfigurationBusinessServicesBuilder
    {
        private readonly FrameworkConfiguration _configuration;

        /// <summary>
        /// 
        /// </summary>
        protected FrameworkConfiguration Configuration
        {
            get
            {
                return _configuration;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected FrameworkConfigurationBuilder()
        {
            _configuration = new FrameworkConfiguration();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IFrameworkConfigurationBuilder Configure()
        {
            return new FrameworkConfigurationBuilder();
        }

        #region IFrameworkConfigurationDependencyContainerBuilder Members

        /// <summary>
        /// 
        /// </summary>
        /// <param name="newProvider"></param>
        /// <returns></returns>
        public IFrameworkConfigurationServicesBuilder SetLocatorProvider(ServiceLocatorProviderEx newProvider)
        {
            DependencyServiceLocator.SetLocatorProvider(newProvider);
            
            return this;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="newProvider"></param>
        /// <returns></returns>
        public IFrameworkConfigurationServicesBuilder SetLocatorProvider(ServiceLocatorProviderWithLazy newProvider)
        {
            DependencyServiceLocator.SetLocatorProvider(newProvider);
            
            return this;
        }

        #endregion

        #region IFrameworkConfigurationBuilder Members

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IFrameworkConfigurationDependencyContainerBuilder UseDependencyContainer()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IFrameworkConfigurationServicesBuilder Members

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IFrameworkConfigurationBusinessServicesBuilder BusinessServicesConfiguration()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IFrameworkConfigurationDataAccessBuilder DataAccessConfiguration()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 
        /// </summary>
        public void Build()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IFrameworkConfigurationBusinessServicesBuilder Members

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="service"></param>
        /// <returns></returns>
        public IFrameworkConfigurationBusinessServicesBuilder RegisterBusinessService<TEntity, TKey>(IEntityBusinessService<TEntity, TKey> service)
            where TEntity : class, IEntityObject<TKey>
            where TKey : IComparable<TKey>, IEquatable<TKey>
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    public class FrameworkConfiguration
    { 
        
    }
}
